<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@page import="java.io.*" %>
     <%@page import="mavenWebProject.userMapper" %>
     <%@page import="mavenWebProject.user" %>
     <%@page import="mavenWebProject.productsMapper" %>
     <%@page import="mavenWebProject.products" %>
     <%@page import="mavenWebProject.order" %>
     <%@page import="mavenWebProject.car" %>
     <%@page import="java.util.*" %>
     <%@page import="javax.servlet.*" %>
     <%@page import="org.apache.ibatis.io.Resources" %>
     <%@page import="org.apache.ibatis.session.SqlSession"%>
     <%@page import="org.apache.ibatis.session.SqlSessionFactory" %>
     <%@page import="org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员</title>
</head>

<style>
    body{font-family: 楷体;font-size: 18px;}

    table[id="tableGuide"]{
        position: absolute;
        top:0%;
        left:0%;
        width:100%;
        height:200px;
        background-color: black;
        color:white;
    }

    table[id="tableMainScene"]{display:block;position: absolute;top:60px;left:0px;background-color:rgb(241,245,251);width:100%;height:700px;border-top-left-radius: 10px;border-top-right-radius: 10px;}
    
    a:link{color:black;text-decoration:none;padding:10px;}
    a:hover{padding:8px;border-radius: 5px;background-color: aliceblue;color: black;}
    a[id="hrefa"]{color:white;}
    a[id="hrefa"]:hover{color:black;}
    a[id="tableProductsManageSearchButton"]{margin-left:20px;padding:8px;background-color:white;border-radius:8px;}

    p{margin:0px;}
</style>

<body>
    
    <%
    String username=String.valueOf(session.getAttribute("username"));
    %>
    
    <table id="tableGuide" border="0" cellspacing="10px">
        <tr></tr>
        <tr><td width="30px"></td><td width="60px"><a onClick="showMainScene()">首页</a></td><td width="100px"><a id="hrefa" href="managerManageProducts.jsp">商品管理</a></td><td width="100px"><a id="hrefa" href="managerManageOrder.jsp">订单管理</a></td><td width="100px"><a id="hrefa" href="managerShowSold.jsp">销量排行</a></td><td width="100px"><a id="hrefa" href="managerManagePurchaser.jsp">用户情况</a></td><td width="100px"></td><td align="right" width="800px">欢迎您：<font style="font-size:24px;margin:10px;color:cyan;"><%=username%></font>&nbsp;&nbsp;<a style="color:red" onClick="exit()">注销</a></td></tr>
        <tr><td colspan="8" height="150px"></tr>
    </table>
    <script>

        function exit(){document.location.href="loadIn.jsp";}

    </script>


	<%
	String resource = "mybatis-config.xml";
	InputStream inputStream = Resources.getResourceAsStream(resource);
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
	SqlSession sqlsession=sqlSessionFactory.openSession();
	
	userMapper userMapper=sqlsession.getMapper(userMapper.class);
	productsMapper productsMapper=sqlsession.getMapper(productsMapper.class);
	
	List<user> user=userMapper.selectAllUser();
	List<user> user1=userMapper.selectByUsername("系统账户");int allInCome=0;
	for(user s:user1){allInCome=s.getMoney();}
	List<user> loadInNum=userMapper.selectLoadInNum("统计网页访问次数");
	String stage1="确认收货";String stage2="待发货";String stage3="待收货";
	List<order> order1=productsMapper.selectOrderByStage(stage1);
	List<order> order2=productsMapper.selectOrderByStage(stage2);
	List<order> order3=productsMapper.selectOrderByStage(stage3);
	
	int confirmedOrder=0;int onSellOrder=0;int recievedOrder=0;
	for(order s:order1){confirmedOrder++;}for(order s:order2){onSellOrder++;}for(order s:order3){recievedOrder++;}
	int userNum=-2;//有个记录访问次数的记录条
	for(user s:user){userNum++;}
	int loadInTimes=0;
	for(user s:loadInNum){loadInTimes=s.getTime();}
	Date date=new Date();
	String time=(1900+date.getYear())+"年"+(date.getMonth()+1)+"月"+date.getDate()+"日";
	int todayOrder=0;int allTimeOrder=0;int todayIncome=0;int doneIncome=0;int tradeIncome=0;
	List<order> allOrders=productsMapper.selectAllOrders();
	for(order s:allOrders){if(s.getOpentime().trim().contentEquals(time)){todayOrder++;todayIncome+=s.getAmount()*s.getPrice();}allTimeOrder++;}
	int productsNum=0;
	for(order s:allOrders){productsNum+=s.getAmount();if(s.getStage().trim().contentEquals("确认收货")){doneIncome+=s.getPrice()*s.getAmount();}else{tradeIncome+=s.getPrice()*s.getAmount();}}
	List<order> userOrder=productsMapper.selectDistinctOrder();int count=0;
	for(order s:userOrder){count++;}
	int average=(doneIncome+tradeIncome)/count;
	//4.执行方法
	request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");
	%>
    <table id="tableMainScene" border="0" cellspacing="20px">
    <tr>
        <td height="150px" colspan="3" valign="top"><font style="color:blue;font-size:22px;font-weight:bolder;">|首页</font>
        <p style="font-size:35px;margin-top:10px;margin-bottom:5px;font-weight: bold;">今天，</p><p style="font-size:15px;"><%=time%>，欢迎登入BI购物平台管理系统，平台累计售出<font style="font-size:24px;margin:10px;"><%=productsNum%></font>件商品，继续加油~</p>
        <p style="font-size:20px;">目前总收益：<font style="font-size:30px;color:red;font-weight:bold;">￥<%=allInCome%></font></p></td>
        <td colspan="2" align="right">
            <table border="0">
                <tr><td width="80px"></td><td width="80px" height="150px" align="right"><img src="Imgs/onSell.png" width="70px"></td><td width="140px" align="center"><p style="font-size:24px;"><%=onSellOrder+recievedOrder%></p><p style="font-size:14px;">售中商品</p></td><td width="65px" align="right"><img src="Imgs/onRoad.png" width="75px"></td><td width="100px" align="center"><p style="font-size:24px;"><%=recievedOrder%></p><p style="font-size:14px;">已发货</p></td><td width="80px" align="right"><img src="Imgs/recieve.png" width="60px"></td><td width="100px" align="center"><p style="font-size:24px;"><%=confirmedOrder%></p><p style="font-size:14px;">已收货</p></td><td width="50px"></td></tr>
            </table>
        </td>
    </tr>
    <tr>
        <td width="200"></td>
        <td width="450" height="200px">
            <table border="0" style="background-color:white;box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
                <tr><td height="20px" width="150px">&nbsp;平台访问情况</td><td colspan="2" width="300px"></td></tr>
                <tr><td align="center" width="150px" height="150px" rowspan="2"><img src="Imgs/users.png" style="border-radius:100px;" width="80px" height="80px"></td>
                    <td height="180px" width="80px" valign="middle" rowspan="2" colspan="2">·注册用户数：<font style="font-size:24px;color:red;">&nbsp;&nbsp;&nbsp;&nbsp;<%=userNum%></font><br><br>·平台访问次数：<font style="font-size:24px;color:red">&nbsp;&nbsp;<%=loadInTimes%></font></td></tr>
            </table>
        </td>
        <td width="328">
            <table border="0" style="background-color:white;box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
            <tr><td height="20px" width="100px">&nbsp;订单数</td><td colspan="2" width="228px"></td></tr>
            <tr><td align="center" width="100px" height="150px" rowspan="2"><img src="Imgs/showOrder.png" style="border-radius:100px;" width="80px" height="80px"></td>
                <td height="180px" width="160px" valign="middle" rowspan="2" colspan="2">今日订单：<font style="font-size:24px;color:red;"> <%=todayOrder%></font><br><br>总订单：<font style="font-size:24px;color:red;">&nbsp; <%=allTimeOrder%></font></td></tr>
            </table>
        </td>
        <td width="328">
            <table border="0" style="background-color:white;box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
                <tr><td height="20px" width="100px">&nbsp;预计收入</td><td colspan="2" width="228px"></td></tr>
                <tr><td align="center" width="100px" height="150px" rowspan="2"><img src="Imgs/showIncome.png" style="border-radius:100px;" width="80px" height="80px"></td>
                    <td height="180px" width="160px" valign="middle" rowspan="2" colspan="2">今日预估收入：<font style="font-size:24px;color:red;"><br>￥<%=todayIncome%></font></td></tr>
            </table>
        </td>
        <td width="200">&nbsp;</td>
    </tr>
    <tr><td></td><td width="450" height="200">
        <table border="0" style="background-color:white;box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
            <tr><td align="center" width="150px" height="200px" rowspan="2"><img src="Imgs/showShopDatas.png" style="border-radius:100px;" width="80px" height="80px"></td>
                <td height="200px" width="300px" valign="middle" rowspan="2" colspan="2"><p style="font-size:30px;margin-bottom:10px">BI SHOP</p>创建日期：2022-5-01<br>已经营：<font style="font-size:24px;color:red;"><%=(date.getTime()-1651389802745l)/1000/60/60/24%></font>天<br><br><a onClick="goMainScene()" style="color:blue;padding:8px;background-color:cyan;border-radius:10px;">前往平台首页</a></td></tr>
        </table>
    </td><td colspan="2">
        <table border="0" style="background-image:url(Imgs/showTrade.png);background-size: contain;background-color:rgb(255, 255, 255);box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
            <tr><td colspan="4" height="20px" width="656px">&nbsp;交易情况</td></tr>
            <tr><td width="218px" height="90px" align="center" valign="bottom"><p style="font-size:26px;color:red;font-weight: bold;"><%=confirmedOrder+recievedOrder%>/<%=confirmedOrder+onSellOrder+recievedOrder%></p></td><td align="center" valign="bottom" width="218px"><p style="font-size:26px;color:red;font-weight: bold;"><%=doneIncome%>/<%=doneIncome+tradeIncome%></p></td><td align="center" valign="bottom" width="218px"><p style="font-size:26px;color:red;font-weight: bold;"><%=average%></p></td></tr>
            <tr><td align="center" height="50px" valign="top"><p style="font-size:16px;">成交数/交易数（件）</p></td><td align="center" valign="top"><p style="font-size:16px;">成交额/交易额（元）</p></td><td align="center" valign="top"><p style="font-size:16px;">人均消费（元）</p></td></tr>
       		<tr><td height="40px" colspan="4" align="right"><a onClick="showDetail()" style="margin:0px;color:blue;font-size:20px;">详情...</a></td></tr>
        </table>
    </td><td></td></tr>
    </table>
    <table id="tableDetail" border="0" cellspacing="0" style="display:none;font-size:20px;position:absolute;top:250px;left:200px;width:1100px;background-color:rgb(255, 255, 255);box-shadow:3px 3px 5px 0px rgba(0, 0, 0, 0.5);border-radius: 10px;">
            <tr align="center" style="font-size:24px"><td height="50px" width="250px">购买用户</td><td width="250px">产品名称</td><td width="150px">价格（元）</td><td width="150px">数量（件）</td><td width="80px">尺码</td><td width="100px">状态</td><td width="100px" align="right"><a onClick="hideDetail()" style="color:red;font-size:25px;font-weight:bold;">×</a>&nbsp;&nbsp;</td></tr><tr><td colspan='6'><hr></td></tr>
            <%if(!allOrders.isEmpty()){for(order s:allOrders){out.println("<tr align='center'><td>"+s.getUsername()+"</td><td>"+s.getName()+"</td><td>"+s.getPrice()+"</td><td>"+s.getAmount()+"</td><td>"+s.getSize()+"</td><td>"+s.getStage()+"</td><td></td></tr><tr><td colspan='6'><hr></td></tr>");}}else{out.println("<td align='center' colspan='7' style='font-size:28px;margin:15px;color:red;'>暂无订单</td>");}%>
   			<%if(!allOrders.isEmpty()){%><tr align="center" style="font-size:24px"><td height="50px" width="300px"></td><td width="300px"></td><td width="100px"><%=doneIncome+tradeIncome%></td><td width="100px"><%=productsNum%></td><td width="100px"></td><td width="100px"></td><td width="80px" align="right"></td></tr><%}%>
    </table>
    <script>
        function goMainScene(){document.location.href="mainScene.jsp?identity=manager";}
        function showDetail(){document.getElementById("tableDetail").style.display="block";}
        function hideDetail(){document.getElementById("tableDetail").style.display="none";}
    </script>

</body>
</html>